﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NapCardOnline.Models
{
    public partial class Cost
    {
        /// <summary>
        /// Gets the cost by service id.
        /// </summary>
        /// <param name="serviceId">The service id.</param>
        /// <returns>The list of cost</returns>
        public static List<Cost> GetListCostByServiceId(int serviceId)
        {
            using (var db = new NapCardOnlineEntities())
            {
                var serviceCostList = db.ServiceCosts.Where(s => s.FK_ServiceID == serviceId).ToList();
                return serviceCostList.Select(serviceCost => GetCostByCostId(serviceCost.FK_CostID)).ToList();
            }
        }
        /// <summary>
        /// Gets the cost by cost id.
        /// </summary>
        /// <param name="costId">The cost id.</param>
        /// <returns>
        /// The Cost object
        /// </returns>
        public static Cost GetCostByCostId(int costId)
        {
            using (var db = new NapCardOnlineEntities())
            {
                return db.Costs.FirstOrDefault(c => c.CostID == costId);
            }
        }

        public static int GetCostIdByServiceCostId(int serviceCostId)
        {
            using (var db = new NapCardOnlineEntities())
            {
                var objServiceCost = db.ServiceCosts.FirstOrDefault(s => s.ServiceCostID == serviceCostId);
                if (objServiceCost != null)
                {
                    return objServiceCost.FK_CostID;
                }
                return 0;
            }
        }
    }
}